package com.xk.sport.backend.dao.repository;

import com.xk.sport.backend.dao.model.Community;
import com.xk.sport.backend.dao.model.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface CommunityDao extends JpaRepository<Community, Long>, JpaSpecificationExecutor<Community> {

    @Transactional
    @Modifying
    @Query(value = "delete from community where areaId = ?", nativeQuery = true)
    void deleteCommunitiesByAreaId(long areaId);

    List<Community> findByAreaId(long areaId);

    @Query(value = "select id from community where name like %?1%", nativeQuery = true)
    Long[] findIdsByName(String name);

    @Query(value = "select * from community where id in (?1)", nativeQuery = true)
    List<Community> findCommunitiesByIds(List<Long> ids);
}
